/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package gsoc.ogsadai.model.impl;

import gsoc.ogsadai.model.DataType;
import gsoc.ogsadai.model.InputStreamType;
import gsoc.ogsadai.model.InputType;
import gsoc.ogsadai.model.ModelPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Input Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link gsoc.ogsadai.model.impl.InputTypeImpl#getInputStream <em>Input Stream</em>}</li>
 *   <li>{@link gsoc.ogsadai.model.impl.InputTypeImpl#getInputLiteral <em>Input Literal</em>}</li>
 *   <li>{@link gsoc.ogsadai.model.impl.InputTypeImpl#getName <em>Name</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class InputTypeImpl extends EObjectImpl implements InputType {
	/**
	 * The cached value of the '{@link #getInputStream() <em>Input Stream</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInputStream()
	 * @generated
	 * @ordered
	 */
	protected InputStreamType inputStream;

	/**
	 * The cached value of the '{@link #getInputLiteral() <em>Input Literal</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInputLiteral()
	 * @generated
	 * @ordered
	 */
	protected EList<DataType> inputLiteral;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected InputTypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ModelPackage.Literals.INPUT_TYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InputStreamType getInputStream() {
		return inputStream;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetInputStream(InputStreamType newInputStream, NotificationChain msgs) {
		InputStreamType oldInputStream = inputStream;
		inputStream = newInputStream;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ModelPackage.INPUT_TYPE__INPUT_STREAM, oldInputStream, newInputStream);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setInputStream(InputStreamType newInputStream) {
		if (newInputStream != inputStream) {
			NotificationChain msgs = null;
			if (inputStream != null)
				msgs = ((InternalEObject)inputStream).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ModelPackage.INPUT_TYPE__INPUT_STREAM, null, msgs);
			if (newInputStream != null)
				msgs = ((InternalEObject)newInputStream).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ModelPackage.INPUT_TYPE__INPUT_STREAM, null, msgs);
			msgs = basicSetInputStream(newInputStream, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.INPUT_TYPE__INPUT_STREAM, newInputStream, newInputStream));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DataType> getInputLiteral() {
		if (inputLiteral == null) {
			inputLiteral = new EObjectContainmentEList<DataType>(DataType.class, this, ModelPackage.INPUT_TYPE__INPUT_LITERAL);
		}
		return inputLiteral;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.INPUT_TYPE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ModelPackage.INPUT_TYPE__INPUT_STREAM:
				return basicSetInputStream(null, msgs);
			case ModelPackage.INPUT_TYPE__INPUT_LITERAL:
				return ((InternalEList<?>)getInputLiteral()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ModelPackage.INPUT_TYPE__INPUT_STREAM:
				return getInputStream();
			case ModelPackage.INPUT_TYPE__INPUT_LITERAL:
				return getInputLiteral();
			case ModelPackage.INPUT_TYPE__NAME:
				return getName();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ModelPackage.INPUT_TYPE__INPUT_STREAM:
				setInputStream((InputStreamType)newValue);
				return;
			case ModelPackage.INPUT_TYPE__INPUT_LITERAL:
				getInputLiteral().clear();
				getInputLiteral().addAll((Collection<? extends DataType>)newValue);
				return;
			case ModelPackage.INPUT_TYPE__NAME:
				setName((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ModelPackage.INPUT_TYPE__INPUT_STREAM:
				setInputStream((InputStreamType)null);
				return;
			case ModelPackage.INPUT_TYPE__INPUT_LITERAL:
				getInputLiteral().clear();
				return;
			case ModelPackage.INPUT_TYPE__NAME:
				setName(NAME_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ModelPackage.INPUT_TYPE__INPUT_STREAM:
				return inputStream != null;
			case ModelPackage.INPUT_TYPE__INPUT_LITERAL:
				return inputLiteral != null && !inputLiteral.isEmpty();
			case ModelPackage.INPUT_TYPE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //InputTypeImpl
